package xcmg.syn.service.demo;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.syn.dao.entity.demo.DemoDO;
import xcmg.syn.dao.mapper.demo.DemoMapper;
import xcmg.syn.infra.BeanUtil;
import xcmg.syn.service.vo.demo.DemoVO;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;
import yb.ecp.fast.infra.util.PageHelperPlus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by john on 2017/10/13.
 */
@Service
public class DemoService {
    @Autowired
    private DemoMapper demoMapper;

    public PageCommonVO<DemoVO> list(SearchCommonVO<DemoVO> condition) {
        PageCommonVO<DemoVO> pageCommonVO = new PageCommonVO<>();
        PageHelperPlus.orderBy("ORG_ID desc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<DemoDO> doList = demoMapper.queryList(condition.getFilters());
        List<DemoVO> voList = new ArrayList<>();
        for (DemoDO entity : doList) {
            voList.add(BeanUtil.do2bo(entity, DemoVO.class));
        }
        pageCommonVO.setPageInfo(new PageInfo<>(doList));
        pageCommonVO.setPageInfoList(voList);
        return pageCommonVO;
    }

}
